package com.zx.cloud.model.request;

import java.time.OffsetDateTime;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.zx.cloud.util.converter.jackson.OffsetDateTimeToIso8601Serializer;

import lombok.EqualsAndHashCode;
import lombok.ToString;

/**
 * @author Alex
 */
@ToString
@EqualsAndHashCode
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(value = {"hibernateLazyInitializer", "handler", "fieldHandler"}, ignoreUnknown = true)
public class RestfulRequest implements Request {
	
    private static final long serialVersionUID = -2363877433041183308L;

    protected Integer pageIndex=1;
    protected Integer pageSize = 20;
    @JsonIgnore
    protected Integer limitStart;
    @JsonIgnore
    protected Integer limitEnd;
    protected String orderBy;
    @JsonIgnore
    protected String keyword;
    @JsonSerialize(using = OffsetDateTimeToIso8601Serializer.class)
    protected OffsetDateTime startTime;
    @JsonSerialize(using = OffsetDateTimeToIso8601Serializer.class)
    protected OffsetDateTime endTime;
    
	public OffsetDateTime getStartTime() {
		return startTime;
	}

	public void setStartTime(OffsetDateTime startTime) {
		this.startTime = startTime;
	}

	public OffsetDateTime getEndTime() {
		return endTime;
	}

	public void setEndTime(OffsetDateTime endTime) {
		this.endTime = endTime;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}
	
	@JsonIgnore 
	public Integer getPageIndex_() {
		return pageIndex;
	}
	
	@JsonIgnore
	public Integer getPageSize_() {
		return pageSize;
	}

	public Integer getLimitStart() {
        if (pageIndex != null && pageIndex >=1 && pageSize != null && pageSize > 0) {
            limitStart = (pageIndex-1) * pageSize;
        }
        return limitStart;
    }

    public void setLimitStart(Integer limitStart) {
        this.limitStart = limitStart;
    }

    public Integer getLimitEnd() {
        if (pageIndex != null && pageIndex >= 0 && pageSize != null && pageSize > 0) {
            limitEnd = pageSize;
        }
        return limitEnd;
    }

    public Integer getPageIndex() {
		return pageIndex;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

	public void setLimitEnd(Integer limitEnd) {
        this.limitEnd = limitEnd;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }
    
}
